<?php
namespace Endpoints\CandyTech;

use Endpoints\Base\Endpoint;
use Endpoints\Tools\GetOssObject;
use Models\Candy\Content;
use Symfony\Component\Console\Input\InputArgument;

class IndexTech extends Endpoint
{
    // 定义参数



    // 收参
    public function getArguments()
    {
        return [
            [static::ARGUMENT_PAGE,InputArgument::OPTIONAL,'页数',1],
            [static::ARGUMENT_P_LIMIT,InputArgument::OPTIONAL,'获取多少数据','10'],
        ];
    }

    /**
     * 实现逻辑
     * @return \Laravelladder\Core\Collections\BaseCollection
     */
    public function dryRun()
    {
        $page   = $this->argument(static::ARGUMENT_PAGE);
        $limit  = $this->argument(static::ARGUMENT_P_LIMIT);
        $offset = $limit * (($page > 0 ? $page : 1) - 1);


        $sql = "SELECT
                    :select_columns
                FROM
                    hi_candy_tech AS tech
                WHERE
                    tech.deleted_at IS NULL ";


        $sql .= " :order_by :pagination ";

        $list = $this
            ->getUniRepo()
            ->sqlSelectListWithPagination(
                $sql,
                [

                ],
                [
                    '*',
                ],
                $limit,
                $offset,
                ['tech.date'=>'desc','tech.id'=>'desc']
                );
        $list->each(function(&$item){
            /**
             * @var $item \Laravelladder\Core\Models\UniModel
             */
            $showDate = substr($item['date'],2,10);
            $item->addFillable('show_date',$showDate);
        });
        return $list;
    }
}